package com.hunttown.mes.convert;

import com.google.common.collect.Lists;
import com.hunttown.mes.common.utils.BeanUtils;
import com.hunttown.mes.domain.AnalysisManageLoginLog;
import com.hunttown.mes.rpc.domain.AnalysisManageLoginLogDTO;
import com.hunttown.mes.rpc.domain.enums.ErrorCode;
import com.hunttown.mes.rpc.exception.ConvertException;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.List;

/**
 * created by wangjunfu on 2018-11-26 15:05:26
 */
public class AnalysisManageLoginLogConverts {

    private static Logger LOG = LoggerFactory.getLogger(AnalysisManageLoginLogConverts.class);

    public static List<AnalysisManageLoginLogDTO> convert(List<AnalysisManageLoginLog> analysisManageLoginLogList) {
        if (CollectionUtils.isEmpty(analysisManageLoginLogList)) {
            return Collections.EMPTY_LIST;
        }

        List<AnalysisManageLoginLogDTO> analysisManageLoginLogListResult = Lists.newArrayList();
        for (AnalysisManageLoginLog analysisManageLoginLog : analysisManageLoginLogList) {
            analysisManageLoginLogListResult.add(convert(analysisManageLoginLog));
        }
        return analysisManageLoginLogListResult;
    }

    public static AnalysisManageLoginLogDTO convert(AnalysisManageLoginLog analysisManageLoginLog) {
        try {
            return BeanUtils.copy(analysisManageLoginLog, AnalysisManageLoginLogDTO.class);
        } catch (Exception e) {
            LOG.error("AnalysisManageLoginLog到AnalysisManageLoginLogDTO转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "AnalysisManageLoginLog到AnalysisManageLoginLogDTO转换失败", e);
        }
    }

    public static AnalysisManageLoginLog convert(AnalysisManageLoginLogDTO analysisManageLoginLogDTO) {
        try {
            return BeanUtils.copy(analysisManageLoginLogDTO, AnalysisManageLoginLog.class);
        } catch (Exception e) {
            LOG.error("AnalysisManageLoginLogDTO到AnalysisManageLoginLog转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "AnalysisManageLoginLogDTO到AnalysisManageLoginLog转换失败", e);
        }
    }
}